{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a9e2de66",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "137\n"
     ]
    }
   ],
   "source": [
    "def is_leap_year(year):\n",
    "    return (year % 4 == 0 and year % 100!= 0) or year % 400 == 0\n",
    "\n",
    "def day_of_year(year, month, day):\n",
    "    days_of_month = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n",
    "    if is_leap_year(year):\n",
    "        days_of_month[2] = 29\n",
    "    total_days = 0\n",
    "    for m in range(1, month):\n",
    "        total_days += days_of_month[m]\n",
    "    total_days += day\n",
    "    return total_days\n",
    "\n",
    "year = int(input(\"请输入年份: \"))\n",
    "month = int(input(\"请输入月份: \"))\n",
    "day = int(input(\"请输入日期: \"))\n",
    "print(day_of_year(year, month, day))\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aaf222c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1000以内的素数个数为: 168\n",
      "1000以内的素数分别为: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]\n"
     ]
    }
   ],
   "source": [
    "prime_numbers = []\n",
    "for num in range(2, 1001):\n",
    "    is_prime = True\n",
    "    for i in range(2, int(num ** 0.5) + 1):\n",
    "        if num % i == 0:\n",
    "            is_prime = False\n",
    "            break\n",
    "    if is_prime:\n",
    "        prime_numbers.append(num)\n",
    "\n",
    "print(\"1000以内的素数个数为:\", len(prime_numbers))\n",
    "print(\"1000以内的素数分别为:\", prime_numbers)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3b67a12",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入学习成绩: 89\n",
      "该成绩对应的等级是: B\n"
     ]
    }
   ],
   "source": [
    "score = float(input(\"请输入学习成绩: \"))\n",
    "grade = \"A\" if score >= 90 else (\"B\" if 60 <= score < 90 else \"C\")\n",
    "print(\"该成绩对应的等级是:\", grade)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cbcdb79f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一行字符串: mb/,5613\n",
      "英文字母个数: 2\n",
      "空格个数: 0\n",
      "数字个数: 4\n",
      "其它字符个数: 2\n"
     ]
    }
   ],
   "source": [
    "s = input(\"请输入一行字符串: \")\n",
    "letter_count = 0\n",
    "space_count = 0\n",
    "digit_count = 0\n",
    "other_count = 0\n",
    "for char in s:\n",
    "    if char.isalpha():\n",
    "        letter_count += 1\n",
    "    elif char.isspace():\n",
    "        space_count += 1\n",
    "    elif char.isdigit():\n",
    "        digit_count += 1\n",
    "    else:\n",
    "        other_count += 1\n",
    "\n",
    "print(\"英文字母个数:\", letter_count)\n",
    "print(\"空格个数:\", space_count)\n",
    "print(\"数字个数:\", digit_count)\n",
    "print(\"其它字符个数:\", other_count)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b244fb6a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "28\n",
      "496\n"
     ]
    }
   ],
   "source": [
    "for num in range(1, 1001):\n",
    "    factor_sum = 0\n",
    "    for factor in range(1, num):\n",
    "        if num % factor == 0:\n",
    "            factor_sum += factor\n",
    "    if factor_sum == num:\n",
    "        print(num)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d701ed65",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个整数N: 256\n",
      "861181818558606182414326253106656143673388993752210343984277535388511795703967906373695892961825990976944497860028660042564022655363986917722694174885618493544534045964299882650498468298989901291332735152002405906541336788804082089965862335028892093490153339919113036602318732156886953129731282419323862096916514114407478893299808855110793055250564121527605779782739809165695559435094877986566624674308537848499937034797210729985660229212293975479478684738621107994804323593105039052556442336528920420940313\n"
     ]
    }
   ],
   "source": [
    "N = int(input(\"请输入一个整数N: \"))\n",
    "sum_result = 0\n",
    "factorial = 1\n",
    "for n in range(1, N + 1):\n",
    "    factorial *= n\n",
    "    sum_result += factorial\n",
    "\n",
    "print(sum_result)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ce1c4398",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个奇数N: 7\n",
      "   *\n",
      "  ***\n",
      " *****\n",
      "*******\n",
      " *****\n",
      "  ***\n",
      "   *\n"
     ]
    }
   ],
   "source": [
    "N = int(input(\"请输入一个奇数N: \"))\n",
    "# 上半部分\n",
    "for i in range(N // 2 + 1):\n",
    "    print(\" \" * (N // 2 - i) + \"*\" * (2 * i + 1))\n",
    "# 下半部分\n",
    "for j in range(N // 2):\n",
    "    print(\" \" * (j + 1) + \"*\" * (N - 2 * (j + 1))）\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8d8e6d3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请依次输入10个数字:\n",
      "1\n",
      "15\n",
      "14\n",
      "16\n",
      "14\n",
      "18\n",
      "58\n",
      "98\n",
      "48\n",
      "56\n",
      "排序后的结果: [1, 14, 14, 15, 16, 18, 48, 56, 58, 98]\n"
     ]
    }
   ],
   "source": [
    "nums = []\n",
    "print(\"请依次输入10个数字:\")\n",
    "for _ in range(10):\n",
    "    num = int(input())\n",
    "    nums.append(num)\n",
    "\n",
    "sorted_nums = sorted(nums)\n",
    "print(\"排序后的结果:\", sorted_nums)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f0b25615",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个数: 25\n",
      "[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 25]\n"
     ]
    }
   ],
   "source": [
    "sorted_list = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]  # 示例已排好序的数组，可替换为实际的数组\n",
    "num = int(input(\"请输入一个数: \"))\n",
    "inserted = False\n",
    "for i in range(len(sorted_list)):\n",
    "    if num < sorted_list[i]:\n",
    "        sorted_list.insert(i, num)\n",
    "        inserted = True\n",
    "        break\n",
    "if not inserted:\n",
    "    sorted_list.append(num)\n",
    "print(sorted_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4e59fb9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入人数n: 15\n",
      "最后留下的是原来第5号的那位\n"
     ]
    }
   ],
   "source": [
    "n = int(input(\"请输入人数n: \"))\n",
    "nums = list(range(1, n + 1))\n",
    "index = 0\n",
    "count = 0\n",
    "while len(nums) > 1:\n",
    "    index %= len(nums)\n",
    "    count += 1\n",
    "    if count == 3:\n",
    "        del nums[index]\n",
    "        count = 0\n",
    "    else:\n",
    "        index += 1\n",
    "\n",
    "print(\"最后留下的是原来第{}号的那位\".format(nums[0]))\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "adb323e7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
